from huza.base.mainwindow_run import MainWindowRun
from huza.puis.showicon import ShowIcon_Form
from uis.navigate import NaviGate_Form


def connect_exit(self: MainWindowRun):
    exit = self.get_action('exit')
    exit.triggered.connect(self.mainwindow.close)


def connect_showpara(self: MainWindowRun):
    showpara = self.get_action('showpara')
    para_dock = self.get_dock('para')
    para_dock.visibilityChanged.connect(showpara.setChecked)
    showpara.triggered.connect(para_dock.setVisible)


def connect_showinfo(self: MainWindowRun):
    showinfo = self.get_action('showinfo')
    info_dock = self.get_dock('info')
    info_dock.visibilityChanged.connect(showinfo.setChecked)
    showinfo.triggered.connect(info_dock.setVisible)


def connect_t1(self: MainWindowRun):
    t1 = self.get_action('t1')

    def navi():
        self.set_dock_view('navi', '功能', 'para', NaviGate_Form, init_kwargs={'a': 3313})

    t1.triggered.connect(navi)


def connect_t3(self: MainWindowRun):
    t3 = self.get_action('t3')

    def navi():
        if self.get_dock('para').isVisible():
            self.get_dock('para').setVisible(False)
            self.get_dock('setup').setVisible(False)
            self.get_dock('info').setVisible(False)
            self.get_dock('monitor').setVisible(False)
        else:
            self.get_dock('para').setVisible(True)
            self.get_dock('setup').setVisible(True)
            self.get_dock('info').setVisible(True)
            self.get_dock('monitor').setVisible(True)

    t3.triggered.connect(navi)


def connect_showicon(self: MainWindowRun):
    showicon = self.get_action('showicon')

    def showicon_tri():
        self.set_dock_view('icon', '图标', 'main', ShowIcon_Form)

    showicon.triggered.connect(showicon_tri)


def init_connect(self: MainWindowRun):
    connect_exit(self)
    connect_showicon(self)
    connect_showinfo(self)
    connect_showpara(self)
    connect_t1(self)
    connect_t3(self)
